<template>
    <div class="profunplan">
        <el-card shadow="always">
            <div slot="header">
                <span :style="{ fontFamily: '微软雅黑', fontSize: '16px', fontWeight: 'bold' }">公积金方案</span>
            </div>
            <div class="card-body">
                <div>
                    <el-button type="primary" size="default" @click="$router.push('/home/addprofund')">新增</el-button>
                    <el-button type="primary" size="default" plain
                        :style="{ background: '#fff', color: '#409eff' }">删除</el-button>
                </div>
                <div class="tablearea">
                    <el-table ref="multipleTable" :data="tableData" stripe
                        :header-cell-style="{ background: '#f5f7f9', borderTop: '1px solid #ebeef5', textAlign: 'center' }"
                        :cell-style="{ textAlign: 'center' }" style="width: 100%">
                        <el-table-column type="selection" width="60px">
                        </el-table-column>
                        <el-table-column type="index" label="序号" width="60px">
                        </el-table-column>
                        <el-table-column prop="planname" label="方案名称" width="120px">
                        </el-table-column>
                        <el-table-column prop="usenum" label="使用人数" width="80px">
                        </el-table-column>
                        <el-table-column prop="payitem" label="缴纳项目" width="'30%'">
                            <template slot-scope="scope">
                                <el-tag v-for="tag, index in scope.row.payitem" :key="index" type="info"
                                    :style="{ marginRight: '5px', width: '70px' }">
                                    {{ tag }}
                                </el-tag>
                            </template>
                        </el-table-column>
                        <el-table-column prop="status" label="状态" width="80px">
                            <template slot-scope="scope">
                                <div>
                                    <el-switch @change="changeStatus(scope.row)" :value="scope.row.status == 1">
                                    </el-switch>
                                </div>
                            </template>
                        </el-table-column>
                        <el-table-column prop="founder" label="创建人" width="120px">
                        </el-table-column>
                        <el-table-column label="创建时间" width="160px">
                            <template slot-scope="scope">{{ scope.row.date | date }}</template>
                        </el-table-column>
                        <el-table-column label="操作" width="'30%'">
                            <template slot-scope="scope">
                                <div class="handle">
                                    <el-button type="text" @click="dialogLinkVisible = true">关联员工</el-button>
                                    <el-button type="text"
                                        @click="$router.push('/home/editprofund/?plan=' + scope.row.planname)">编辑</el-button>
                                    <el-button type="text"
                                        @click="$router.push('/home/editprofund/?plan=' + scope.row.planname)">复制</el-button>
                                    <el-button type="text" :style="{ color: '#c00' }"
                                        @click="delinfo(scope.row)">删除</el-button>
                                </div>
                            </template>
                        </el-table-column>
                    </el-table>
                </div>
            </div>
            <el-row>
                <el-col :span="24" :style="{ textAlign: 'right' }">
                    <el-pagination background @size-change="handleSizeChange" @current-change="handleCurrentChange"
                        :current-page="currentPage4" layout="total, prev, pager, next" :total="6">
                    </el-pagination>
                </el-col>
            </el-row>
        </el-card>
        <!-- 关联人员的弹框信息 -->
        <el-dialog :visible.sync="dialogLinkVisible" @close="dialogClose">
            <div slot="title" style="padding:0;">
                <span style="font-size: 18px;font-weight: bold;">添加人员</span>
            </div>
            <el-form :inline="true" :model="form" ref="form">
                <el-form-item prop="keyword">
                    <el-input v-model="form.keyword" placeholder="请输入姓名/工号/证件号/手机号" style="width: 250px;"></el-input>
                </el-form-item>
                <el-form-item prop="bumen">
                    <el-input v-model="form.bumen" placeholder="请输入部门" style="width: 200px;">
                        <i slot="suffix" class="el-input__icon el-icon-share"></i>
                    </el-input>
                </el-form-item>
                <el-form-item prop="type">
                    <el-select v-model="form.type" placeholder="请选择活动区域">
                        <el-option label="正式" value="正式"></el-option>
                        <el-option label="试用" value="试用"></el-option>
                    </el-select>
                </el-form-item>
                <el-form-item>
                    <el-button type="primary" @click="chaxun">查询</el-button>
                </el-form-item>
                <el-form-item>
                    <el-button @click="resetForm('form')">重置</el-button>
                </el-form-item>
            </el-form>
            <el-table ref="multipleTable" :data="tableDataShow" stripe
                :header-cell-style="{ background: '#f5f7f9', borderTop: '1px solid #ebeef5', textAlign: 'center' }"
                :cell-style="{ textAlign: 'center' }" style="width: 100%">
                <el-table-column type="selection" width="60px">
                </el-table-column>
                <el-table-column type="index" label="序号" width="60px">
                </el-table-column>
                <el-table-column prop="name" label="姓名" width="120px">
                </el-table-column>
                <el-table-column prop="bumen" label="部门" width="80px">
                </el-table-column>
                <el-table-column prop="zhiwei" label="岗位" width="80px">
                </el-table-column>
                <el-table-column prop="tel" label="手机号" width="'20%'">
                </el-table-column>
                <el-table-column prop="gonghao" label="工号" width="'20%'">
                </el-table-column>
                <el-table-column prop="zhengjian" label="证件号" width="'20%'">
                </el-table-column>
                <el-table-column prop="emptype" label="员工类型" width="100px">
                </el-table-column>
                <el-table-column prop="planname" label="当前方案" width="120px">
                </el-table-column>
                <el-table-column prop="shenbaojishu" label="申报基数" width="100px">
                </el-table-column>
            </el-table>
            <el-row>
                <el-col :span="24" :style="{ textAlign: 'right' }">
                    <el-pagination background @size-change="handleSizeChange" @current-change="handleCurrentChange"
                        :current-page="currentPage4" layout="total, prev, pager, next" :total="10">
                    </el-pagination>
                </el-col>
            </el-row>
            <div slot="footer" class="dialog-footer">
                <el-button @click="dialogClose">取 消</el-button>
                <el-button type="primary" @click="dialogClose">确 定</el-button>
            </div>
        </el-dialog>
    </div>
</template>
<script>
export default {
    name: '',
    components: {

    },
    mixins: [],
    props: {

    },
    data() {
        return {
            currentPage4: 1,
            tableData: [{
                id: 1,
                planname: '方案一',
                usenum: 12,
                payitem: ['公积金', '补充公积金'],
                status: 1,
                founder: '董腾翔',
                date: new Date(),
            }, {
                id: 2,
                planname: '方案二',
                usenum: 12,
                payitem: ['公积金', '补充公积金'],
                status: 1,
                founder: '董腾翔',
                date: new Date(),
            }, {
                id: 3,
                planname: '方案三',
                usenum: 12,
                payitem: ['公积金', '补充公积金'],
                status: 0,
                founder: '董腾翔',
                date: new Date(),
            }, {
                id: 4,
                planname: '方案四',
                usenum: 12,
                payitem: ['公积金', '补充公积金'],
                status: 1,
                founder: '董腾翔',
                date: new Date(),
            }, {
                id: 5,
                planname: '方案五',
                usenum: 12,
                payitem: ['公积金', '补充公积金'],
                status: 0,
                founder: '董腾翔',
                date: new Date(),
            }, {
                id: 6,
                planname: '方案六',
                usenum: 12,
                payitem: ['公积金', '补充公积金'],
                status: 1,
                founder: '董腾翔',
                date: new Date(),
            },],
            multipleSelection: [],
            dialogLinkVisible: false,
            form: {
                keyword: '',
                bumen: '',
                type: '',
            },
            tableData1: [
                {
                    id: 1,
                    name: '莫俏丽',
                    bumen: '项目部',
                    zhiwei: '项目经理',
                    tel: 13714046148,
                    gonghao: 'GH2022011005',
                    zhengjian: 'SFZ20213544',
                    emptype: '正式',
                    planname: '公积金方案一',
                    shenbaojishu: 5869,
                }, {
                    id: 2,
                    name: '令云心',
                    bumen: '项目部',
                    zhiwei: '项目经理',
                    tel: 19893995896,
                    gonghao: 'GH2022011006',
                    zhengjian: 'SFZ20213544',
                    emptype: '正式',
                    planname: '公积金方案二',
                    shenbaojishu: 5869,
                }, {
                    id: 3,
                    name: '堂安春',
                    bumen: '项目部',
                    zhiwei: '项目经理',
                    tel: 15083709763,
                    gonghao: 'GH2021011007',
                    zhengjian: 'SFZ20213544',
                    emptype: '正式',
                    planname: '公积金方案三',
                    shenbaojishu: 5869,
                }, {
                    id: 4,
                    name: '笃水瑶',
                    bumen: '项目部',
                    zhiwei: '项目经理',
                    tel: 15053222627,
                    gonghao: 'GH2021011008',
                    zhengjian: 'SFZ20213544',
                    emptype: '正式',
                    planname: '公积金方案四',
                    shenbaojishu: 5869,
                }, {
                    id: 5,
                    name: '野依云',
                    bumen: '项目部',
                    zhiwei: '项目经理',
                    tel: 13669997085,
                    gonghao: 'GH2021011009',
                    zhengjian: 'SFZ20213544',
                    emptype: '正式',
                    planname: '公积金方案五',
                    shenbaojishu: 5869,
                }, {
                    id: 6,
                    name: '戈元冬',
                    bumen: '项目部',
                    zhiwei: '项目经理',
                    tel: 15080525797,
                    gonghao: 'GH2020011010',
                    zhengjian: 'SFZ20213544',
                    emptype: '正式',
                    planname: '公积金方案一',
                    shenbaojishu: 5869,
                }, {
                    id: 7,
                    name: '闽飞昂',
                    bumen: '项目部',
                    zhiwei: '项目经理',
                    tel: 17882152912,
                    gonghao: 'GH2020011011',
                    zhengjian: 'SFZ20213544',
                    emptype: '正式',
                    planname: '公积金方案二',
                    shenbaojishu: 5869,
                }, {
                    id: 8,
                    name: '闾丘易文',
                    bumen: '项目部',
                    zhiwei: '项目经理',
                    tel: 15725901968,
                    gonghao: 'GH2019011012',
                    zhengjian: 'SFZ20213544',
                    emptype: '正式',
                    planname: '公积金方案三',
                    shenbaojishu: 5869,
                }, {
                    id: 9,
                    name: '曲嘉祥',
                    bumen: '项目部',
                    zhiwei: '项目经理',
                    tel: 13815204688,
                    gonghao: 'GH2019011013',
                    zhengjian: 'SFZ20213544',
                    emptype: '试用',
                    planname: '公积金方案四',
                    shenbaojishu: 5869,
                }, {
                    id: 10,
                    name: '连昌',
                    bumen: '项目部',
                    zhiwei: '项目经理',
                    tel: 15286179282,
                    gonghao: 'GH2019011014',
                    zhengjian: 'SFZ20213544',
                    emptype: '试用',
                    planname: '公积金方案五',
                    shenbaojishu: 5869,
                },
            ],
            tableDataShow: [],
        }
    },
    computed: {

    },
    watch: {

    },
    mounted() {
        this.tableDataShow = this.tableData1
    },
    methods: {
        handleSizeChange(val) {
            console.log(`每页 ${val} 条`);
        },
        handleCurrentChange(val) {
            console.log(`当前页: ${val}`);
        },
        delinfo(row) {
            if (row.status == 1) {
                this.$message({
                    showClose: true,
                    message: '使用中方案，不可删除！',
                    type: 'error'
                });
            }
            this.$message({
                showClose: true,
                message: '方案未使用，删除成功',
                type: 'success'
            });
        },
        resetForm(formName) {
            this.$refs.form.resetFields();
            this.tableDataShow = this.tableData1
        },
        chaxun() {
            if (this.form.keyword) {
                let keyword = this.form.keyword
                console.log(keyword[0]);
                if (keyword[0] == 'G') {
                    this.tableDataShow = this.tableData1.filter(item => item.gonghao === keyword)
                } else if (keyword[0] == 'S') {
                    this.tableDataShow = this.tableData1.filter(item => item.zhengjian === keyword)
                } else if (keyword[0] == '1') {
                    this.tableDataShow = this.tableData1.filter(item => item.tel === parseInt(keyword))
                } else {
                    console.log(keyword);
                    this.tableDataShow = this.tableData1.filter(item => item.name === keyword)
                }
            } else if (this.form.bumen) {
                this.tableDataShow = this.tableData1.filter(item => item.bumen === this.form.bumen)
            } else if (this.form.type) {
                this.tableDataShow = this.tableData1.filter(item => item.emptype === this.form.type)
            }
        },
        dialogClose() {
            this.dialogLinkVisible = false;
            this.tableDataShow = this.tableData1;
            this.$refs.form.resetFields();
        },
        changeStatus(row) {
            const idx = this.tableData.findIndex(item => item.id === row.id)
            let status = this.tableData[idx].status
            if (status == 1) {
                this.tableData[idx].status = 0
            } else {
                this.tableData[idx].status = 1
            }
        }
    }
};
</script>
<style lang='less'>
.profunplan {
    width: 100%;
    height: 100%;
    box-sizing: border-box;

    .el-card {
        width: 100%;

        .card-body {
            width: 100%;

            .tablearea {
                width: 100%;

                .el-table {
                    width: 100%;
                    margin: 20px 0;

                    .handle {
                        width: 100%;
                        display: flex;
                        justify-content: space-around;
                        align-items: center;
                    }
                }
            }

            .el-table::before {
                height: 0;
            }
        }
    }

    .el-dialog {
        width: 60%;
    }

    .el-dialog__body {
        padding: 10px 20px;

        .el-table {
            margin-bottom: 15px;
        }
    }
}
</style>